package org.gdstash.util;

import org.gdstash.db.DBBitmap;
import org.gdstash.db.DBCaravanWindow;
import org.gdstash.db.DBInventoryGrid;
import org.gdstash.ui.GDStashFrame;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class GDImagePool {
    public static ImageIcon iconProgress;
    public static ImageIcon iconLoading;
    public static ImageIcon iconLogo64x64;
    public static ImageIcon iconBoolOr;
    public static ImageIcon iconBoolOrUnselect;
    public static ImageIcon iconBoolAnd;
    public static ImageIcon iconBoolAndUnselect;
    public static BufferedImage imgDefaultSharedStash;
    public static final int STASH_X_OFFSET = 3;
    public static BufferedImage imgDefaultCharStash;
    public static BufferedImage imgCharBag;
    public static BufferedImage imgCharInventory;
    public static BufferedImage imgCharEquipped;
    public static ImageIcon iconTab;
    public static ImageIcon iconTabHover;
    public static ImageIcon iconTabSelected;
    public static ImageIcon iconMsgError16;
    public static ImageIcon iconMsgInfo16;
    public static ImageIcon iconMsgSuccess16;
    public static ImageIcon iconMsgWarning16;
    public static ImageIcon iconTabCollection16;
    public static ImageIcon iconTabCollectionSet16;
    public static ImageIcon iconTabConfigure16;
    public static ImageIcon iconTabStashCraft16;
    public static ImageIcon iconTabFileImp16;
    public static ImageIcon iconTabStashTransfer16;
    public static ImageIcon iconTabCharEdit16;
    public static ImageIcon iconTabCharData16;
    public static ImageIcon iconTabCharPortal16;
    public static ImageIcon iconTabCharTransfer16;
    public static ImageIcon iconTabMasteryInfo16;
    public static ImageIcon iconCharEditMasteryReset16;
    public static ImageIcon iconPlus16;
    public static ImageIcon iconMinus16;
    public static ImageIcon iconBtnCancel24;
    public static ImageIcon iconBtnDir24;
    public static ImageIcon iconBtnFilter24;
    public static ImageIcon iconBtnOk24;
    public static ImageIcon iconBtnQuestion24;
    public static ImageIcon iconBtnReload24;
    public static ImageIcon iconBtnSave24;
    public static ImageIcon iconBtnSearch24;
    public static ImageIcon iconBtnTrash24;
    public static ImageIcon iconWindowCollapse24;
    public static ImageIcon iconWindowExpand24;
    public static ImageIcon iconDBDelete24;
    public static ImageIcon iconItemCopy24;
    public static ImageIcon iconItemDelete24;
    public static ImageIcon iconItemMove24;
    public static ImageIcon iconPageCopy24;
    public static ImageIcon iconPageDelete24;
    public static ImageIcon iconPageMove24;
    public static ImageIcon iconCollectAll24;
    public static ImageIcon iconCollectFound24;
    public static ImageIcon iconCollectMiss24;
    public static ImageIcon iconConfigARZExport24;
    public static ImageIcon iconConfigDBImport24;
    public static ImageIcon iconConfigTransmuteAdd24;
    public static ImageIcon iconConfigTransmuteFull24;
    public static ImageIcon iconConfigDevotionList24;
    public static ImageIcon iconConfigTextureConvert24;
    public static ImageIcon iconConfigSettingSave24;
    public static ImageIcon iconMassAll24;
    public static ImageIcon iconMassNone24;
    public static ImageIcon iconMassGDSExport24;
    public static ImageIcon iconMassGDSLoad24;
    public static ImageIcon iconMassIASLoad24;
    public static ImageIcon iconMassItemImport24;
    public static ImageIcon iconMassItemLoad24;
    public static ImageIcon iconMassUniqueClipboard24;
    public static ImageIcon iconMassLegendClipboard24;
    public static ImageIcon iconMassBlueprints24;
    public static ImageIcon iconMassValid24;
    public static ImageIcon iconTransGDSExport24;
    public static ImageIcon iconMsgError32;
    public static ImageIcon iconMsgInfo32;
    public static ImageIcon iconMsgSuccess32;
    public static ImageIcon iconMsgWarning32;
    public static BufferedImage imgBorderSquare;
    public static BufferedImage imgBorderRound;
    public static BufferedImage tileTopLeft;
    public static BufferedImage tileTopRight;
    public static BufferedImage tileTop;
    public static BufferedImage tileBottomLeft;
    public static BufferedImage tileBottomRight;
    public static BufferedImage tileBottom;
    public static BufferedImage tileCenterLeft;
    public static BufferedImage tileCenterRight;
    public static BufferedImage tileCenter;
    public static BufferedImage tileNoise;
    private static BufferedImage imgSharedStash;
    private static int sharedXOffset;
    private static int sharedYOffset;
    private static BufferedImage imgCraftingStash;
    private static int craftingXOffset;
    private static int craftingYOffset;
    private static BufferedImage imgCharStash;
    private static BufferedImage imgCharBG;
    private static int charXOffset;
    private static int charYOffset;
    public static final int STASH_Y_OFFSET = 3;
    private static BufferedImage imgCharBackground;

    public static void loadLogos() {
        BufferedImage image = null;
        try {
            image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GDS_Logo.png"));
            GDImagePool.iconLogo64x64 = new ImageIcon(image);
        } catch (IOException ex) {
        }
        try {
            image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GDStash_Progress_1.png"));
            GDImagePool.iconProgress = new ImageIcon(image);
        } catch (IOException ex2) {
        }
        try {
            if (GDStashFrame.expansionFangsOfAsterkarn) {
                image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GDStash_Load_5.png"));
            } else if (GDStashFrame.expansionForgottenGods) {
                image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GDStash_Load_4.png"));
            } else if (GDStashFrame.expansionAshesOfMalmouth) {
                image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GDStash_Load_3.png"));
            } else {
                image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GDStash_Load_2.png"));
            }
            GDImagePool.iconLoading = new ImageIcon(image);
        } catch (IOException ex3) {
        }
    }

    public static void loadTiles() {
        BufferedImage image = null;
        try {
            image = (GDImagePool.imgCharBackground = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_Char_BG.png")));
        } catch (IOException ex) {
        }
        try {
            image = (GDImagePool.imgDefaultSharedStash = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_SharedStash_Tiles.png")));
        } catch (IOException ex2) {
        }
        try {
            image = (GDImagePool.imgDefaultCharStash = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_CharStash_Tiles.png")));
        } catch (IOException ex3) {
        }
        try {
            image = (GDImagePool.imgCharInventory = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_CharInventory_Tiles.png")));
        } catch (IOException ex4) {
        }
        try {
            image = (GDImagePool.imgCharEquipped = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_Char_Equipment_Tiles.png")));
        } catch (IOException ex5) {
        }
        try {
            image = (GDImagePool.imgCharBag = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_CharBag_Tiles.png")));
        } catch (IOException ex6) {
        }
        try {
            image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_Tab.png"));
            GDImagePool.iconTab = new ImageIcon(image);
        } catch (IOException ex7) {
        }
        try {
            image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_Tab_Hover.png"));
            GDImagePool.iconTabHover = new ImageIcon(image);
        } catch (IOException ex8) {
        }
        try {
            image = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "GD_Tab_Selected.png"));
            GDImagePool.iconTabSelected = new ImageIcon(image);
        } catch (IOException ex9) {
        }
        try {
            image = (GDImagePool.tileTopLeft = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_TopLeft.png")));
        } catch (IOException ex10) {
        }
        try {
            image = (GDImagePool.tileTopRight = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_TopRight.png")));
        } catch (IOException ex11) {
        }
        try {
            image = (GDImagePool.tileTop = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_Top.png")));
        } catch (IOException ex12) {
        }
        try {
            image = (GDImagePool.tileCenterLeft = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_CenterLeft.png")));
        } catch (IOException ex13) {
        }
        try {
            image = (GDImagePool.tileCenterRight = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_CenterRight.png")));
        } catch (IOException ex14) {
        }
        try {
            image = (GDImagePool.tileCenter = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_Center.png")));
        } catch (IOException ex15) {
        }
        try {
            image = (GDImagePool.tileBottomLeft = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_BottomLeft.png")));
        } catch (IOException ex16) {
        }
        try {
            image = (GDImagePool.tileBottomRight = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_BottomRight.png")));
        } catch (IOException ex17) {
        }
        try {
            image = (GDImagePool.tileBottom = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_Bottom.png")));
        } catch (IOException ex18) {
        }
        try {
            image = (GDImagePool.tileNoise = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "tiles" + GDConstants.FILE_SEPARATOR + "Tile_Noise.png")));
        } catch (IOException ex19) {
        }
        buildSharedStash(8, 16);
        buildCraftingStash(8, 16);
        buildCharStash(10, 18);
    }

    public static BufferedImage buildtSharedStashBG(final int width, final int height) {
        int tempwidth = width;
        int tempheight = height;
        if (tempwidth < 0 || tempwidth > 100) {
            if (GDStashFrame.expansionAshesOfMalmouth) {
                tempwidth = 10;
            } else {
                tempwidth = 8;
            }
        }
        if (tempheight < 0 || tempheight > 100) {
            if (GDStashFrame.expansionAshesOfMalmouth) {
                tempheight = 18;
            } else {
                tempheight = 16;
            }
        }
        final int bgH = getSharedStashHeight();
        final int bgW = getSharedStashBGWidth();
        if (tempwidth == bgW && tempheight == bgH) {
            final BufferedImage img = getSharedStashBG();
            if (img != null) {
                return img;
            }
        }
        if (tempwidth == 8 && tempheight == 16) {
            return GDImagePool.imgDefaultSharedStash;
        }
        if (tempwidth == 10 && tempheight == 18) {
            return GDImagePool.imgDefaultCharStash;
        }
        final int tileTopW = GDImagePool.tileTopLeft.getWidth();
        final int tileTopH = GDImagePool.tileTopLeft.getHeight();
        final int tileBottomW = GDImagePool.tileBottomRight.getWidth();
        final int tileBottomH = GDImagePool.tileBottomRight.getHeight();
        final int w = tileTopW + (width - 2) * 32 + tileBottomW;
        final int h = tileTopH + (height - 2) * 32 + tileBottomH;
        final BufferedImage stash = new BufferedImage(w, h, 1);
        final Graphics2D g = stash.createGraphics();
        BufferedImage tile = null;
        int yPos = 0;
        for (int y = 0; y < height; ++y) {
            int xPos = 0;
            for (int x = 0; x < width; ++x) {
                if (y == 0) {
                    if (x == 0) {
                        tile = GDImagePool.tileTopLeft;
                    } else if (x == width - 1) {
                        tile = GDImagePool.tileTopRight;
                    } else {
                        tile = GDImagePool.tileTop;
                    }
                } else if (y == height - 1) {
                    if (x == 0) {
                        tile = GDImagePool.tileBottomLeft;
                    } else if (x == width - 1) {
                        tile = GDImagePool.tileBottomRight;
                    } else {
                        tile = GDImagePool.tileBottom;
                    }
                } else if (x == 0) {
                    tile = GDImagePool.tileCenterLeft;
                } else if (x == width - 1) {
                    tile = GDImagePool.tileCenterRight;
                } else {
                    tile = GDImagePool.tileCenter;
                }
                g.drawImage(tile, xPos, yPos, null);
                xPos += tile.getWidth();
            }
            yPos += tile.getHeight();
        }
        return stash;
    }

    public static int getSharedStashHeight() {
        final DBInventoryGrid grid = DBInventoryGrid.get("records/ui/caravan/caravan_transferinventory.dbr");
        if (grid == null) {
            return -1;
        }
        final int h = grid.getYSize();
        return h / 32;
    }

    public static int getSharedStashBGWidth() {
        final DBInventoryGrid grid = DBInventoryGrid.get("records/ui/caravan/caravan_transferinventory.dbr");
        if (grid == null) {
            return -1;
        }
        final int w = grid.getXSize();
        return w / 32;
    }

    public static BufferedImage getSharedStashBG() {
        final DBBitmap bitmap = DBBitmap.get("records/ui/caravan/caravan_backgroundimage.dbr");
        final DBInventoryGrid grid = DBInventoryGrid.get("records/ui/caravan/caravan_transferinventory.dbr");
        final DBCaravanWindow window = DBCaravanWindow.get("records/ui/caravan/caravan_transferwindow.dbr");
        if (bitmap == null || grid == null || window == null) {
            return null;
        }
        final int x = grid.getXOffset() + window.getXPos();
        final int y = grid.getYOffset() + window.getYPos();
        int w = grid.getXSize();
        int h = grid.getYSize();
        h = h / 32 * 32;
        w = w / 32 * 32;
        BufferedImage img = bitmap.getImage();
        if (img != null) {
            img = img.getSubimage(x, y, w, h);
        }
        final BufferedImage frame = new BufferedImage(img.getWidth() + 6 + 2, img.getHeight() + 6 + 2, img.getType());
        final Graphics2D g = frame.createGraphics();
        g.drawImage(img, 4, 4, null);
        return frame;
    }

    public static void buildSharedStash(final int width, final int height) {
        int tempwidth = width;
        int tempheight = height;
        if (tempwidth < 0 || tempwidth > 100) {
            if (GDStashFrame.expansionAshesOfMalmouth) {
                tempwidth = 10;
            } else {
                tempwidth = 8;
            }
        }
        if (tempheight < 0 || tempheight > 100) {
            if (GDStashFrame.expansionAshesOfMalmouth) {
                tempheight = 18;
            } else {
                tempheight = 16;
            }
        }
        if (tempwidth == 8 && tempheight == 16) {
            GDImagePool.imgSharedStash = GDImagePool.imgDefaultSharedStash;
            GDImagePool.sharedXOffset = 2;
            GDImagePool.sharedYOffset = 2;
            return;
        }
        if (tempwidth == 10 && tempheight == 18) {
            GDImagePool.imgSharedStash = GDImagePool.imgDefaultCharStash;
            GDImagePool.sharedXOffset = 2;
            GDImagePool.sharedYOffset = 2;
            return;
        }
        final int tileTopW = GDImagePool.tileTopLeft.getWidth();
        final int tileTopH = GDImagePool.tileTopLeft.getHeight();
        final int tileBottomW = GDImagePool.tileBottomRight.getWidth();
        final int tileBottomH = GDImagePool.tileBottomRight.getHeight();
        final int w = tileTopW + (width - 2) * 32 + tileBottomW;
        final int h = tileTopH + (height - 2) * 32 + tileBottomH;
        final BufferedImage stash = new BufferedImage(w, h, 1);
        final Graphics2D g = stash.createGraphics();
        BufferedImage tile = null;
        int yPos = 0;
        for (int y = 0; y < height; ++y) {
            int xPos = 0;
            for (int x = 0; x < width; ++x) {
                if (y == 0) {
                    if (x == 0) {
                        tile = GDImagePool.tileTopLeft;
                    } else if (x == width - 1) {
                        tile = GDImagePool.tileTopRight;
                    } else {
                        tile = GDImagePool.tileTop;
                    }
                } else if (y == height - 1) {
                    if (x == 0) {
                        tile = GDImagePool.tileBottomLeft;
                    } else if (x == width - 1) {
                        tile = GDImagePool.tileBottomRight;
                    } else {
                        tile = GDImagePool.tileBottom;
                    }
                } else if (x == 0) {
                    tile = GDImagePool.tileCenterLeft;
                } else if (x == width - 1) {
                    tile = GDImagePool.tileCenterRight;
                } else {
                    tile = GDImagePool.tileCenter;
                }
                g.drawImage(tile, xPos, yPos, null);
                xPos += tile.getWidth();
            }
            yPos += tile.getHeight();
        }
        GDImagePool.imgSharedStash = stash;
        GDImagePool.sharedXOffset = tileTopW - 32;
        GDImagePool.sharedYOffset = tileTopH - 32;
    }

    public static void buildCraftingStash(final int width, final int height) {
        int tempwidth = width;
        int tempheight = height;
        if (tempwidth < 0 || tempwidth > 100) {
            if (GDStashFrame.expansionAshesOfMalmouth) {
                tempwidth = 10;
            } else {
                tempwidth = 8;
            }
        }
        if (tempheight < 0 || tempheight > 100) {
            if (GDStashFrame.expansionAshesOfMalmouth) {
                tempheight = 18;
            } else {
                tempheight = 16;
            }
        }
        if (tempwidth == 8 && tempheight == 16) {
            GDImagePool.imgCraftingStash = GDImagePool.imgDefaultSharedStash;
            GDImagePool.craftingXOffset = 2;
            GDImagePool.craftingYOffset = 2;
            return;
        }
        if (tempwidth == 10 && tempheight == 18) {
            GDImagePool.imgCraftingStash = GDImagePool.imgDefaultCharStash;
            GDImagePool.craftingXOffset = 2;
            GDImagePool.craftingYOffset = 2;
            return;
        }
        final int tileTopW = GDImagePool.tileTopLeft.getWidth();
        final int tileTopH = GDImagePool.tileTopLeft.getHeight();
        final int tileBottomW = GDImagePool.tileBottomRight.getWidth();
        final int tileBottomH = GDImagePool.tileBottomRight.getHeight();
        final int w = tileTopW + (width - 2) * 32 + tileBottomW;
        final int h = tileTopH + (height - 2) * 32 + tileBottomH;
        final BufferedImage stash = new BufferedImage(w, h, 1);
        final Graphics2D g = stash.createGraphics();
        BufferedImage tile = null;
        int yPos = 0;
        for (int y = 0; y < height; ++y) {
            int xPos = 0;
            for (int x = 0; x < width; ++x) {
                if (y == 0) {
                    if (x == 0) {
                        tile = GDImagePool.tileTopLeft;
                    } else if (x == width - 1) {
                        tile = GDImagePool.tileTopRight;
                    } else {
                        tile = GDImagePool.tileTop;
                    }
                } else if (y == height - 1) {
                    if (x == 0) {
                        tile = GDImagePool.tileBottomLeft;
                    } else if (x == width - 1) {
                        tile = GDImagePool.tileBottomRight;
                    } else {
                        tile = GDImagePool.tileBottom;
                    }
                } else if (x == 0) {
                    tile = GDImagePool.tileCenterLeft;
                } else if (x == width - 1) {
                    tile = GDImagePool.tileCenterRight;
                } else {
                    tile = GDImagePool.tileCenter;
                }
                g.drawImage(tile, xPos, yPos, null);
                xPos += tile.getWidth();
            }
            yPos += tile.getHeight();
        }
        GDImagePool.imgCraftingStash = stash;
        GDImagePool.craftingXOffset = tileTopW - 32;
        GDImagePool.craftingYOffset = tileTopH - 32;
    }

    public static void buildCharStash(final int width, final int height) {
        int tempwidth = width;
        int tempheight = height;
        if (tempwidth < 0 || tempwidth > 100) {
            tempwidth = 10;
        }
        if (tempheight < 0 || tempheight > 100) {
            tempheight = 18;
        }
        if (tempwidth == 10 && tempheight == 18) {
            GDImagePool.imgCharStash = GDImagePool.imgDefaultCharStash;
            GDImagePool.imgCharBG = GDImagePool.imgCharBackground;
            GDImagePool.charXOffset = 2;
            GDImagePool.charYOffset = 2;
            return;
        }
        final int tileTopW = GDImagePool.tileTopLeft.getWidth();
        final int tileTopH = GDImagePool.tileTopLeft.getHeight();
        final int tileBottomW = GDImagePool.tileBottomRight.getWidth();
        final int tileBottomH = GDImagePool.tileBottomRight.getHeight();
        int w = tileTopW + (width - 2) * 32 + tileBottomW;
        int h = tileTopH + (height - 2) * 32 + tileBottomH;
        final BufferedImage stash = new BufferedImage(w, h, 1);
        Graphics2D g = stash.createGraphics();
        BufferedImage tile = null;
        int yPos = 0;
        for (int y = 0; y < height; ++y) {
            int xPos = 0;
            for (int x = 0; x < width; ++x) {
                if (y == 0) {
                    if (x == 0) {
                        tile = GDImagePool.tileTopLeft;
                    } else if (x == width - 1) {
                        tile = GDImagePool.tileTopRight;
                    } else {
                        tile = GDImagePool.tileTop;
                    }
                } else if (y == height - 1) {
                    if (x == 0) {
                        tile = GDImagePool.tileBottomLeft;
                    } else if (x == width - 1) {
                        tile = GDImagePool.tileBottomRight;
                    } else {
                        tile = GDImagePool.tileBottom;
                    }
                } else if (x == 0) {
                    tile = GDImagePool.tileCenterLeft;
                } else if (x == width - 1) {
                    tile = GDImagePool.tileCenterRight;
                } else {
                    tile = GDImagePool.tileCenter;
                }
                g.drawImage(tile, xPos, yPos, null);
                xPos += tile.getWidth();
            }
            yPos += tile.getHeight();
        }
        w = tileTopW + (width - 2) * 32 + tileBottomW + 234;
        h = tileTopH + (height - 2) * 32 + tileBottomH + 198;
        final BufferedImage bg = new BufferedImage(w, h, 1);
        g = bg.createGraphics();
        tile = GDImagePool.tileNoise;
        for (int y2 = 0; y2 < h; y2 += tile.getHeight()) {
            for (int x = 0; x < w; x += tile.getWidth()) {
                g.drawImage(tile, x, y2, null);
            }
        }
        GDImagePool.imgCharStash = stash;
        GDImagePool.imgCharBG = bg;
        GDImagePool.charXOffset = tileTopW - 32;
        GDImagePool.charYOffset = tileTopH - 32;
    }

    public static void loadImages() {
        String dir16 = "16";
        String dir17 = "24";
        String dir18 = "32";
        if (GDStashFrame.iniConfig.sectUI.fontSize < 12) {
            dir17 = "16";
            dir18 = "24";
        }
        if (GDStashFrame.iniConfig.sectUI.fontSize > 14) {
            dir16 = "24";
            dir17 = "32";
        }
        if (GDStashFrame.iniConfig.sectUI.fontSize > 16) {
            dir18 = "48";
        }
        dir16 = "image" + GDConstants.FILE_SEPARATOR + "icons" + GDConstants.FILE_SEPARATOR + dir16 + GDConstants.FILE_SEPARATOR;
        dir17 = "image" + GDConstants.FILE_SEPARATOR + "icons" + GDConstants.FILE_SEPARATOR + dir17 + GDConstants.FILE_SEPARATOR;
        dir18 = "image" + GDConstants.FILE_SEPARATOR + "icons" + GDConstants.FILE_SEPARATOR + dir18 + GDConstants.FILE_SEPARATOR;
        BufferedImage image = null;
        try {
            image = ImageIO.read(new File(dir17 + "bool_or_sel.png"));
            GDImagePool.iconBoolOr = new ImageIcon(image);
        } catch (IOException ex) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "bool_or_unsel.png"));
            GDImagePool.iconBoolOrUnselect = new ImageIcon(image);
        } catch (IOException ex2) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "bool_and_sel.png"));
            GDImagePool.iconBoolAnd = new ImageIcon(image);
        } catch (IOException ex3) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "bool_and_unsel.png"));
            GDImagePool.iconBoolAndUnselect = new ImageIcon(image);
        } catch (IOException ex4) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "msg_error.png"));
            GDImagePool.iconMsgError16 = new ImageIcon(image);
        } catch (IOException ex5) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "msg_info.png"));
            GDImagePool.iconMsgInfo16 = new ImageIcon(image);
        } catch (IOException ex6) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "msg_success.png"));
            GDImagePool.iconMsgSuccess16 = new ImageIcon(image);
        } catch (IOException ex7) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "msg_warn.png"));
            GDImagePool.iconMsgWarning16 = new ImageIcon(image);
        } catch (IOException ex8) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_collect.png"));
            GDImagePool.iconTabCollection16 = new ImageIcon(image);
        } catch (IOException ex9) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_collect_set.png"));
            GDImagePool.iconTabCollectionSet16 = new ImageIcon(image);
        } catch (IOException ex10) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_config.png"));
            GDImagePool.iconTabConfigure16 = new ImageIcon(image);
        } catch (IOException ex11) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_file_import.png"));
            GDImagePool.iconTabFileImp16 = new ImageIcon(image);
        } catch (IOException ex12) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_stash_craft.png"));
            GDImagePool.iconTabStashCraft16 = new ImageIcon(image);
        } catch (IOException ex13) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_stash_trans.png"));
            GDImagePool.iconTabStashTransfer16 = new ImageIcon(image);
        } catch (IOException ex14) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_char_edit.png"));
            GDImagePool.iconTabCharEdit16 = new ImageIcon(image);
        } catch (IOException ex15) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_char_data.png"));
            GDImagePool.iconTabCharData16 = new ImageIcon(image);
        } catch (IOException ex16) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_char_portal.png"));
            GDImagePool.iconTabCharPortal16 = new ImageIcon(image);
        } catch (IOException ex17) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_char_trans.png"));
            GDImagePool.iconTabCharTransfer16 = new ImageIcon(image);
        } catch (IOException ex18) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "tab_mastery_info.png"));
            GDImagePool.iconTabMasteryInfo16 = new ImageIcon(image);
        } catch (IOException ex19) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "btn_cancel.png"));
            GDImagePool.iconCharEditMasteryReset16 = new ImageIcon(image);
        } catch (IOException ex20) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "btn_plus.png"));
            GDImagePool.iconPlus16 = new ImageIcon(image);
        } catch (IOException ex21) {
        }
        try {
            image = ImageIO.read(new File(dir16 + "btn_minus.png"));
            GDImagePool.iconMinus16 = new ImageIcon(image);
        } catch (IOException ex22) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_cancel.png"));
            GDImagePool.iconBtnCancel24 = new ImageIcon(image);
        } catch (IOException ex23) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_dir.png"));
            GDImagePool.iconBtnDir24 = new ImageIcon(image);
        } catch (IOException ex24) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_filter.png"));
            GDImagePool.iconBtnFilter24 = new ImageIcon(image);
        } catch (IOException ex25) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_ok.png"));
            GDImagePool.iconBtnOk24 = new ImageIcon(image);
        } catch (IOException ex26) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_question.png"));
            GDImagePool.iconBtnQuestion24 = new ImageIcon(image);
        } catch (IOException ex27) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_reload.png"));
            GDImagePool.iconBtnReload24 = new ImageIcon(image);
        } catch (IOException ex28) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_save.png"));
            GDImagePool.iconBtnSave24 = new ImageIcon(image);
        } catch (IOException ex29) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_search.png"));
            GDImagePool.iconBtnSearch24 = new ImageIcon(image);
        } catch (IOException ex30) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "btn_trash.png"));
            GDImagePool.iconBtnTrash24 = new ImageIcon(image);
        } catch (IOException ex31) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "window_collapse_oxygen.png"));
            GDImagePool.iconWindowCollapse24 = new ImageIcon(image);
        } catch (IOException ex32) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "window_expand_oxygen.png"));
            GDImagePool.iconWindowExpand24 = new ImageIcon(image);
        } catch (IOException ex33) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "db_delete.png"));
            GDImagePool.iconDBDelete24 = new ImageIcon(image);
        } catch (IOException ex34) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "item_copy.png"));
            GDImagePool.iconItemCopy24 = new ImageIcon(image);
        } catch (IOException ex35) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "item_delete.png"));
            GDImagePool.iconItemDelete24 = new ImageIcon(image);
        } catch (IOException ex36) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "item_move.png"));
            GDImagePool.iconItemMove24 = new ImageIcon(image);
        } catch (IOException ex37) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "page_copy.png"));
            GDImagePool.iconPageCopy24 = new ImageIcon(image);
        } catch (IOException ex38) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "page_delete.png"));
            GDImagePool.iconPageDelete24 = new ImageIcon(image);
        } catch (IOException ex39) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "page_move.png"));
            GDImagePool.iconPageMove24 = new ImageIcon(image);
        } catch (IOException ex40) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "coll_all.png"));
            GDImagePool.iconCollectAll24 = new ImageIcon(image);
        } catch (IOException ex41) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "coll_found.png"));
            GDImagePool.iconCollectFound24 = new ImageIcon(image);
        } catch (IOException ex42) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "coll_miss.png"));
            GDImagePool.iconCollectMiss24 = new ImageIcon(image);
        } catch (IOException ex43) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "cfg_arz_exp.png"));
            GDImagePool.iconConfigARZExport24 = new ImageIcon(image);
        } catch (IOException ex44) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "cfg_devotion.png"));
            GDImagePool.iconConfigDevotionList24 = new ImageIcon(image);
        } catch (IOException ex45) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "cfg_texconv.png"));
            GDImagePool.iconConfigTextureConvert24 = new ImageIcon(image);
        } catch (IOException ex46) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "cfg_db_imp.png"));
            GDImagePool.iconConfigDBImport24 = new ImageIcon(image);
        } catch (IOException ex47) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "cfg_save.png"));
            GDImagePool.iconConfigSettingSave24 = new ImageIcon(image);
        } catch (IOException ex48) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "cfg_transmute_add.png"));
            GDImagePool.iconConfigTransmuteAdd24 = new ImageIcon(image);
        } catch (IOException ex49) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "cfg_transmute_full.png"));
            GDImagePool.iconConfigTransmuteFull24 = new ImageIcon(image);
        } catch (IOException ex50) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_all.png"));
            GDImagePool.iconMassAll24 = new ImageIcon(image);
        } catch (IOException ex51) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_none.png"));
            GDImagePool.iconMassNone24 = new ImageIcon(image);
        } catch (IOException ex52) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_valid.png"));
            GDImagePool.iconMassValid24 = new ImageIcon(image);
        } catch (IOException ex53) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_gds_exp.png"));
            GDImagePool.iconMassGDSExport24 = new ImageIcon(image);
        } catch (IOException ex54) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_gds_load.png"));
            GDImagePool.iconMassGDSLoad24 = new ImageIcon(image);
        } catch (IOException ex55) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_ias_load.png"));
            GDImagePool.iconMassIASLoad24 = new ImageIcon(image);
        } catch (IOException ex56) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_item_imp.png"));
            GDImagePool.iconMassItemImport24 = new ImageIcon(image);
        } catch (IOException ex57) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_item_load.png"));
            GDImagePool.iconMassItemLoad24 = new ImageIcon(image);
        } catch (IOException ex58) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_item_export.png"));
            GDImagePool.iconMassUniqueClipboard24 = new ImageIcon(image);
        } catch (IOException ex59) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_legend_export.png"));
            GDImagePool.iconMassLegendClipboard24 = new ImageIcon(image);
        } catch (IOException ex60) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "mass_formula.png"));
            GDImagePool.iconMassBlueprints24 = new ImageIcon(image);
        } catch (IOException ex61) {
        }
        try {
            image = ImageIO.read(new File(dir17 + "trans_exp.png"));
            GDImagePool.iconTransGDSExport24 = new ImageIcon(image);
        } catch (IOException ex62) {
        }
        try {
            image = ImageIO.read(new File(dir18 + "msg_error.png"));
            GDImagePool.iconMsgError32 = new ImageIcon(image);
        } catch (IOException ex63) {
        }
        try {
            image = ImageIO.read(new File(dir18 + "msg_info.png"));
            GDImagePool.iconMsgInfo32 = new ImageIcon(image);
        } catch (IOException ex64) {
        }
        try {
            image = ImageIO.read(new File(dir18 + "msg_success.png"));
            GDImagePool.iconMsgSuccess32 = new ImageIcon(image);
        } catch (IOException ex65) {
        }
        try {
            image = ImageIO.read(new File(dir18 + "msg_warn.png"));
            GDImagePool.iconMsgWarning32 = new ImageIcon(image);
        } catch (IOException ex66) {
        }
        try {
            image = (GDImagePool.imgBorderSquare = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "skills_buttonborder01.png")));
        } catch (IOException ex67) {
        }
        try {
            image = (GDImagePool.imgBorderRound = ImageIO.read(new File("image" + GDConstants.FILE_SEPARATOR + "skills_buttonborderround01.png")));
        } catch (IOException ex68) {
        }
    }

    public static BufferedImage getSharedStashGrid() {
        return GDImagePool.imgSharedStash;
    }

    public static int getSharedStashXOffset() {
        return GDImagePool.sharedXOffset;
    }

    public static int getSharedStashYOffset() {
        return GDImagePool.sharedYOffset;
    }

    public static BufferedImage getCraftingStashGrid() {
        return GDImagePool.imgCraftingStash;
    }

    public static int getCraftingStashXOffset() {
        return GDImagePool.craftingXOffset;
    }

    public static int getCraftingStashYOffset() {
        return GDImagePool.craftingYOffset;
    }

    public static BufferedImage getCharStashGrid() {
        return GDImagePool.imgCharStash;
    }

    public static BufferedImage getCharStashBG() {
        return GDImagePool.imgCharBG;
    }

    public static BufferedImage copyImage(final BufferedImage source) {
        final BufferedImage img = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
        final Graphics g = img.getGraphics();
        g.drawImage(source, 0, 0, null);
        g.dispose();
        return img;
    }
}
